package com.hongkzh.www.look.media.view.adapter;

import android.annotation.SuppressLint;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.hongkzh.www.R;
import com.hongkzh.www.look.media.model.bean.Top10Bean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by asad on 2018/3/23.
 * 自媒体 排行 adapter
 */

public class MedTopRvAdapter extends RecyclerView.Adapter<MedTopRvAdapter.ViewHolder> {
    private List<Top10Bean.DataBean> data = new ArrayList<>();

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_medtoprv, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, @SuppressLint("RecyclerView") final int position) {
        Glide.with(holder.itemView).load(data.get(position).getCoverImgSrc()).into(holder.medtoprvIma);
//        holder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (onItemClickListener != null)
//                    onItemClickListener.onItemClick(data.get(position).getUid(), data.get(position).getId());
//            }
//        });
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size() >= 4 ? 4 : data.size();
    }

    public void add(Top10Bean top10Bean) {
        data = top10Bean.getData();
    }

    public interface OnItemClickListener {
        void onItemClick(String uid, String id);
    }

    private OnItemClickListener onItemClickListener;

    void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.medtoprv_ima)
        ImageView medtoprvIma;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
